package com.wanpinghui.supplier.user.company.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wanpinghui.supplier.R;
import com.wanpinghui.wphlibrary.model.user.bean.CaseBean;
import com.yunshl.yunshllibrary.recyclerview.BaseRecyclerViewAdapter;
import com.yunshl.yunshllibrary.utils.TimeUtil;

/**
 * Created by tg596 on 2018/1/29.
 */

public class ProjectCaseAdapter extends BaseRecyclerViewAdapter<CaseBean,ProjectCaseAdapter.CompanyProjectCaseViewHolder> {

    public ProjectCaseAdapter(Context context) {
        super(context);
    }

    @Override
    public CompanyProjectCaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_project_cases,parent,false);
        return new CompanyProjectCaseViewHolder(view);
    }

    @Override
    public void onBindViewHolder(CompanyProjectCaseViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        CaseBean bean = datas.get(position);
        Glide.with(context).load(bean.getPictures()+"_thumbnail").thumbnail(0.5f).placeholder(R.mipmap.loading_140x140).into(holder.image_view);
        holder.tv_time.setText(TimeUtil.format(bean.getCase_date()*1000, "yyyy-MM-dd"));
        holder.tv_name.setText(bean.getCase_name());
        holder.tv_area.setText(bean.getCase_area());

    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size() ;
    }

    class  CompanyProjectCaseViewHolder extends ViewHolder {
        TextView tv_name;
        TextView tv_area;
        TextView tv_time;
        ImageView image_view;

        public CompanyProjectCaseViewHolder(View itemView) {
            super(itemView);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_area = (TextView) itemView.findViewById(R.id.tv_area);
            tv_time = (TextView) itemView.findViewById(R.id.tv_time);
            image_view = (ImageView) itemView.findViewById(R.id.image_view);
        }
    }
}
